package com.service;


import com.qqcommon.Message;

import java.io.ObjectInputStream;
import java.net.Socket;

/**
 *
 */
public class ClientConnectServerThread extends Thread{
    //该线程持有socket
    private Socket socket;

    //构造器:可以接受一个Socket对象
    public  ClientConnectServerThread(Socket socket){
        this.socket=socket;
    }

    //方便得到Socket
    public Socket getSocket() {
        return socket;
    }

    @Override
    public void run() {
        //因为Thread需要在后台和服务器保持通信,所以用while循环
        while(true){
            try {
                System.out.println("客户端线程,等待读取从服务端发来的消息");
                ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
                //如果服务器没有发送信息,Thread会阻塞在这
                Message message=(Message) ois.readObject();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
